﻿<script type="text/template" id="basicsetting-template">
    <div class="page-dialog" style="width:602px;">
        <el-form ref="form" :rules="rules" :model="model" label-width="80px">
            <el-form-item prop="SecretKey" label="系统密钥">
                <el-input v-model="model.SecretKey"></el-input>
            </el-form-item>
            <el-form-item prop="DefaultRoleID" label="默认角色">
                <el-select ref="role" v-model="model.DefaultRoleID" style="width:100%">
                    <el-option v-for="item in roles" :key="item.ID" :label="item.Title" :value="item.ID"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="Copyright" label="版权信息">
                <page-editor v-model="model.Copyright" height="150" editorRef="editor"></page-editor>
            </el-form-item>
            <div></div>
        </el-form>
    </div>
</script>
<script type="text/javascript">
    var basicsetting = {
        template: "#basicsetting-template",
        data: function () {
            return {
                model: {
                    SecretKey: "",
                    DefaultRoleID: "",
                    Copyright: ""
                },
                roles: [],
                rules: {
                    SecretKey: [{ required: true, message: "请填写功能标题", trigger: "blur" }]
                }
            }
        },
        methods: {
            loadModel: function () {
                var that = this;
                workVue.ajax({
                    url: "/basic/setting/get",
                    target: that.$parent.$el,
                    success: function (result) {
                        that.model = result.data;
                    }
                });
                workVue.dialog.handle = that.submitForm;
            },
            loadRoles: function () {
                var that = this;
                workVue.ajax({
                    url: "/basic/role/gridall",
                    target: that.$refs.role.$el,
                    success: function (result) {
                        that.roles = result.data;
                    }
                });
            },
            submitForm: function () {
                var that = this;
                that.$refs.form.validate((valid) => {
                    if (valid) {
                        workVue.ajax({
                            url: "/basic/setting/set",
                            type: "post",
                            data: { model: that.model },
                            target: that.$parent.$el,
                            success: function (result) {
                                workVue.dialog.visible = false;
                                that.$message.success(result.message);
                            }
                        });
                    }
                })
            },
            closeDialog: function () {
                workVue.dialog.visible = false;
            }
        },
        mounted: function () {
            this.loadModel();
            this.loadRoles();
        }
    }
</script>